package com.qdu.servlet;

import com.qdu.entity.Book;
import com.qdu.service.BookService;
import com.qdu.service.CommentService;
import com.qdu.service.impl.BookServiceImpl;
import com.qdu.service.impl.CommentServiceImpl;
import java.io.IOException;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * 根据电影编号查询单个电影所有信息的Servlet
 *
 * @author Anna
 */
@WebServlet("/gbis")
public class GetBookInfoServlet extends HttpServlet {

    BookService bookService = new BookServiceImpl();
    CommentService commentService = new CommentServiceImpl();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        //1. 获取请求参数
        //获取提交的图书编号
        String bookId = req.getParameter("bId");
        
        //
        String mbid = req.getParameter("bId");
        List<Object[]> commentList = commentService.findCommentListByMBId(mbid);
        HttpSession session = req.getSession();
        session.setAttribute("commentList", commentList);
        //

        //2. 执行业务逻辑 
        //调用BookService类的findBookById()方法根据图书编号查询图书所有信息
    
        Book book = bookService.findBookById(bookId);

       
        req.setAttribute("book", book);
        req.getRequestDispatcher("/book_info2.jsp").forward(req, resp);
    }
}
